<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>项目管理</title>
  <style>

  </style>
</head>
<body>


<button class="btn">防抖</button>
<button class="jl-btn">节流</button>
<script>

  function debounce(func, wait) {
    let timeout;
    return function(...args) {
      const context = this;
      clearTimeout(timeout);
      timeout = setTimeout(() => func.apply(context, args), wait);
    };
  }

  // 用法示例
  const debouncedFunction = debounce(() => {
    console.log('Debounced function executed');
  }, 300);
  // 节流
  function throttle(func, limit) {
    let inThrottle;
    return function(...args) {
      const context = this;
      if (!inThrottle) {
        func.apply(context, args);
        inThrottle = true;
        setTimeout(() => inThrottle = false, limit);
      }
    };
  }

  // 用法示例
  const throttledFunction = throttle(() => {
    console.log('Throttled function executed');
  }, 300);

  // 绑定到事件
  window.addEventListener('scroll', throttledFunction);

  // 绑定到事件
  let btn =document.querySelector('.btn')
  let jlBtn =document.querySelector('.jl-btn')
  console.log(btn,'sad');
  btn.addEventListener('click', debouncedFunction);
  jlBtn.addEventListener('click', debouncedFunction);


  let trainForm= {
    projectName: undefined,
    version: undefined,
    description: undefined,
    fileList: [],
    type: undefined,pageNo: 1,
    pageSize: 999999,
    templateTaskId: undefined,
    templateStageId: undefined
  }
  function reset(data) {
    for (let key in data) {
      if (data.hasOwnProperty(key)) {
        if (Array.isArray(data[key])) {
          data[key] = [];
        } else if (typeof data[key] === 'object' && data[key] !== null) {
          data[key] = {};
        } else {
          if (key === 'pageSize') {
            data[key] = 999999;
          } else if (key === 'pageNo') {
            data[key] = 1;
          } else {
            data[key] = undefined;
          }
        }
      }
    }
    return data; // 返回重置后的数据
  }
  reset(trainForm)
  console.log(trainForm);
</script>
</body>
</html>
